<template>
  <div
    id="cctaskdetail"
    v-loading="loading"
  >
    <v-tableTitle
      :btnConfig="btnConfig"
      :tableSelectData="tableSelectData"
      :title="$t('work.tasktotal')"
      @del="del"
      @writeactualstock="writeactualstock"
      @writestocknull="writestocknull"
    ></v-tableTitle>
    <v-table
      :hasEdit="false"
      :pageSize="pageSize"
      :page="page"
      :tableConfig="tableConfig"
      :tableData="tableData"
      :total="total"
      @findData="getTableData"
      @getTableData="getTableData"
      @searhData="searhData"
      @selectData="selectData"
      @upData="getTableData"
      ref="table"
    ></v-table>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";
import bus from "../../../../bus/bus"

export default {
  name: "cctaskdetail",
  mixins: [baseMixin, config],
  data () {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('ex.taskdetailkey'),
          prop: "taskdetailkey",
          input: "input",
        },
        {
          label: this.$t('common.type'),
          prop: "tasktype",
          input: "select",
          options: this.getOptions("querycodeLkup/LADYCCTASKTYPE")
        },
        {
          label: this.$t('home.subkey'),
          prop: "sourcekey",
          input: "input",
        },
        {
          label: this.$t('ex.taskgroup'),
          prop: "taskgroupkey",
          input: "input",
        },
        {
          label: this.$t('config.area'),
          prop: "area",
          input: "input"
        },
        {
          label: this.$t('config.area'),
          prop: "putawayzone",
          input: "input"
        },
        {
          label: this.$t('config.loc'),
          prop: "fromloc",
          input: "input"
        },
        {
          label: this.$t('in.lpn'),
          prop: "fromid",
          input: "input"
        },
        {
          label: this.$t('config.sku'),
          prop: "sku",
          input: "input"
        },
        {
          label: this.$t('home.qty'),
          prop: "qty",
          input: "input"
        },
        {
          label: this.$t('home.inventory'),
          prop: "ccqty",
          input: "input"
        },
        {
          label: this.$t('work.editwho'),
          prop: "userkey",
          input: "input"
        },
        {
          label: this.$t('out.starttime'),
          prop: "starttime",
          input: "date"
        },
        {
          label: this.$t('out.endtime'),
          prop: "endtime",
          input: "date"
        },
        {
          label: this.$t('common.status'),
          prop: "status",
          input: "select",
          options: this.getOptions("querycodeLkup/TMSTATUS")
        },
        {
          label: this.$t('work.ccmirroringnum'),
          prop: "udf2",
          input: "input"
        }
      ],
      tableData: [],
      pageSize: 10,
      page: 1,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
    };
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('common.delete'), certigier: this.deleteStatus||!this.btnPermNameList.includes('WM06040301'), disabled: true, invalid: "del" },
        {
          label: this.$t('work.writeactulstock'),
          certigier: this.writeActualStockStatus||!this.btnPermNameList.includes('WM06040302'),
          disabled: true,
          invalid: "writeactualstock"
        },
        { label: this.$t('work.writestocknull'), certigier: this.writeStockNullStatus||!this.btnPermNameList.includes('WM06040303'), disabled: true, invalid: "writestocknull" },
      ]
    }
  },
  created () {
  },
  methods: {
    async writeactualstock (data) {
      try {
        let res = await this.$api.post(`/rtx_cc_taskdetailAction/WRITEACTUALSTOCK`, data);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem('page');
          this.getTableData(page, this.tableSearhData);
          
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    async writestocknull (data) {
      try {
        let res = await this.$api.post(`/rtx_cc_taskdetailAction/WRITESTOCKNULL`, data);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem('page');
          this.getTableData(page, this.tableSearhData);
          
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //选中的内容
    selectData (data) {
      this.tableSelectData = data;
    },
    //删除
    async del (data) {
      try {
        let res = await this.$api.post(`/rtx_cc_taskdetailAction/DELCCTASKDEL`, data);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem('page');
          this.getTableData(page, this.tableSearhData);
          
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    async getTableData (page, data) {
      try {
        this.loading = true;
        let res = await this.$api.post(`/queryRtx_cctaskdetailList/${page}`, data);
        
          this.tableData = res.page.list;
          this.page = res.page.curPage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.loading = false;
      }
    },
    //搜索的值
    searhData (data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
  },
  mounted () {
    
    this.$store.commit("setSkip", {});
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setTemporary", "");
    this.$store.commit("setRouteData", {});
    this.getTableData(1, {});
  },
  watch: {
    tableSelectData (data) {
      if (this.permissionStatus) {
        if (data.length > 0) {
          this.deleteStatus = this.writeActualStockStatus = this.writeStockNullStatus = false;
        } else {
          this.deleteStatus = this.writeActualStockStatus = this.writeStockNullStatus = true;
        }
      }
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table,
  }
};
</script>

<style scoped>
#cctaskdetail {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
